//
//  DLMachineFormContentTC.m
//  delongzhitou
//
//  Created by Mr.Wang on 2018/12/2.
//  Copyright © 2018 delongzhitou. All rights reserved.
//

#import "DLMachineFormContentTC.h"


@implementation DLMachineFormContentTC


- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self layoutsubControls];
    }
    return self;
}
- (void) layoutsubControls {
    
    
}

- (void) setFormContentDataSource:(NSArray *)formContentDataSource {
    _formContentDataSource = formContentDataSource;
    
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    for (NSInteger i = 1; i < formContentDataSource.count; i++) {
        
        UILabel *contentLabel = [UILabel new];
        contentLabel.frame = CGRectMake(kMachineFormContentTitleLabelWidth * (i - 1), 0, kMachineFormContentTitleLabelWidth, kMachineFormTitleLabelHeight);
        
        contentLabel.textAlignment = NSTextAlignmentCenter;
        contentLabel.font = kSystemFont(12);
        [self.contentView addSubview:contentLabel];
        contentLabel.backgroundColor = [UIColor blackColor];
        contentLabel.backgroundColor = kColorRGB(46, 56, 70);
        contentLabel.backgroundColor = [UIColor whiteColor];
        contentLabel.tag = 1000 + i;
        NSString *contentStr = [NSString stringWithFormat:@"%@", formContentDataSource[i]];
        
        contentLabel.text = contentStr;
        
//        if (contentStr.length > 10) {
//            NSString *newContentStr = [contentStr substringToIndex:10];
//            contentLabel.text = newContentStr;
//        } else {
//            contentLabel.text = contentStr;
//        }
        
        if (i == 1) {
            contentLabel.textColor = kColorRGB(60, 163, 242);
        } else {
            contentLabel.textColor = kColorRGB(85, 85, 85);
        }
        
        contentLabel.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(contentLabelTap:)];
        [contentLabel addGestureRecognizer:tapGes];
    }
}
- (void) contentLabelTap:(UITapGestureRecognizer *)tapGes {
    
    UILabel *tapLabel = (UILabel *)tapGes.view;
    
    CGFloat labelTextWidth = 0;
    labelTextWidth = [tapLabel.text getValue4WidWithHeight:kMachineFormTitleLabelHeight andFont:kSystemFont(12)];

    if (labelTextWidth > 100) {
        if (self.labelTapBlock) {
            self.labelTapBlock(tapLabel);
        }
    }
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
